package com.cn.kehong.controller;


import com.cn.kehong.api.IPlanYearService;
import com.cn.kehong.api.IThroughRateService;
import com.cn.kehong.domain.PlanYear;
import com.cn.kehong.domain.ThroughRate;
import com.cn.kehong.domain.ThroughRateVo;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/rate")
public class ThroughRateController {

    @Autowired
    private IThroughRateService throughRateService;

    @RequestMapping("/getThroughRateList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ThroughRate>> getThroughRateList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ThroughRate>> response = new JsonResponse<List<ThroughRate>>();
        List<ThroughRate> list  = throughRateService.getThroughRateList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getThroughRateVoList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ThroughRateVo>> getThroughRateVoList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ThroughRateVo>> response = new JsonResponse<List<ThroughRateVo>>();
        List<ThroughRateVo> list  = throughRateService.getThroughRateVoList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getThroughRateTimes/{frontToken}")
    @ResponseBody
    public JsonResponse<List<String>> getThroughRateTimes(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<String>> response = new JsonResponse<List<String>>();
        List<String> list  = throughRateService.getThroughRateTimes();
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/addThroughRate/{frontToken}")
    public JsonResponse<String> addThroughRate(@RequestBody ThroughRate throughRate, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = throughRateService.addThroughRate(throughRate);
        return CommonUtil.getResponseData(response,result);
    }


    @ResponseBody
    @RequestMapping("/updateThroughRate/{frontToken}")
    public JsonResponse<String> updateThroughRate(@RequestBody ThroughRate throughRate, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = throughRateService.updateThroughRate(throughRate);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deleteThroughRateById/{frontToken}")
    public JsonResponse<String> deleteThroughRateById(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = throughRateService.deleteThroughRateById(id);
        return CommonUtil.getResponseData(response,result);
    }

}
